package com.lsy.weizhi2.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.lsy.weizhi2.JsonObject.ReplyList;
import com.lsy.weizhi2.R;
import com.lsy.weizhi2.config.Constants;
import com.lsy.weizhi2.myutils.ReplyUserItemCall;

/**
 * Created by 嗨哟 on 2017/3/16.
 */
public class ReplyUserItem extends RelativeLayout{
    private Context context;
    private ImageView reply_image;
    private TextView reply_name,reply_user_status,reply_time,reply_close;
    private ReplyUserItemCall replyUserItemCall;
    public ReplyUserItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        LayoutInflater.from(context).inflate(R.layout.reply_user_item,this,true);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        reply_image= (ImageView) findViewById(R.id.reply_image);
        reply_name= (TextView) findViewById(R.id.reply_name);
        reply_user_status= (TextView) findViewById(R.id.reply_user_status);
        reply_time= (TextView) findViewById(R.id.reply_time);
        reply_close= (TextView) findViewById(R.id.reply_close);
        reply_user_status.setVisibility(View.GONE);//目前没有先关闭
        reply_close.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                replyUserItemCall.onClick(view,ReplyUserItemCall.DELETE);
            }
        });
        reply_image.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                replyUserItemCall.onClick(view,ReplyUserItemCall.HEAD_IMAGE);
            }
        });
    }
    //设定网络获取的信息
    public void setInfo(ReplyList.ListBean bean){
        if(bean!=null){
                Glide.with(context).load(Constants.SERVICE_IP+"")
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .error(R.mipmap.default_head)
                        .transform(new GlideCircleTransform(context))
                        .into(reply_image);
            reply_name.setText(bean.getRealName());
            //reply_user_status.setText("");
            reply_time.setText(bean.getCreateTime());
        }
    }

    public void setReply_close(String str){
        reply_close.setText(str);
    }

    public void hideReply_close(){
        reply_close.setVisibility(View.GONE);
    }

    public String getReply_close(){
        return reply_close.getText().toString().trim();
    }

    public void setReplyUserItemCall(ReplyUserItemCall replyUserItemCall){
        this.replyUserItemCall=replyUserItemCall;
    }
}
